from base.java.exception.IllegalStateException import IllegalStateException
from base.util.iterator.ExtendedIterator import ExtendedIterator


class IteratorImpl(ExtendedIterator):

    def __init__(self, elements):
        self.container = elements
        self.idx = -1

    '''
        一开始 idx = -1 这时候调用remove 需要报错，以为没有先移动到有索引值的地方
    '''
    def next(self):
        if self.idx >= len(self.container):
            raise IllegalStateException('already end of the iterator')

        item = self.container[self.idx]
        self.idx = self.idx + 1
        return item

    def hasNext(self):
        return self.idx < len(self.container)

    def remove(self):
        del self.container[self.idx]

